<template>
	<!-- 确定订单 -->
	<view class="box public">
		<view class="top">
			<!-- text为ture 自提按钮 -->
			<template>
				<view class="Pick-up-at-home">
					<!-- 按钮 -->
					<view class="Button" @click="textfalse"
						style="width: 157rpx;height: 45rpx;background-color:rgb(249,178,150) ; border-radius: 22rpx;display: flex;">
						<view class="Button-left"
							:style="text == 1 ? 'float: left; width: 110rpx; text-align: center; background-color: #f14500; border-radius: 22rpx;' : 'float: left; width: 90rpx; text-align: center;border-radius: 22rpx;'">
							<text style="height: 100%; color: #fff; font-size: 20rpx;">{{ text == 1 ? '自提' : '自提' }}</text>
						</view>
						<view class="Button-right"
							:style="text == 2 ? 'float: right; width: 110rpx; text-align: center; background-color: #f14500; border-radius: 22rpx;' : 'float: right; width: 90rpx; text-align: center;border-radius: 22rpx;'">
							<text style="height: 100%; color: #fff; font-size: 20rpx;">{{ text == 2 ? '外卖' : '外卖' }}</text>
						</view>
					</view>
					<!-- selectAddress -->
					<view class="dizhi" v-if="text == 1">
						<text class="Pick-shopping">{{ shopAddress.site_name }}</text>
						<text class="Pick-address">{{ shopAddress.address }} {{ shopAddress.address }}</text>
					</view>
					<view class="dizhi" v-else @click="selectAddress">
						<view class="" v-if="addresskong == true">
							<text class="Pick-shopping">{{ waimaiaddress.address }} {{ waimaiaddress.house_number }}</text>
							<text class="Pick-address">{{ waimaiaddress.name }} {{ waimaiaddress.mobile }}</text>
						</view>
						<view class="" v-else>
							<text class="quxuanzeaddress">去选择收货地址</text>
						</view>
					</view>
					<view class="" v-if="text == 1">
						<view class="Pick-time">
							<text class="time">取餐时间</text>
							<!-- 取餐时间 -->
							<view class="time-qu">
								<text style="color: #F14500" v-if="dateTimeShow">{{ dateTime.month }}月{{ dateTime.day }}日{{ dateTime.hour
								}}:{{ dateTime.minute }}</text>
								<uni-icons type="forward" @click="dateShow = true"></uni-icons>
								<u-picker v-model="dateShow" mode="time" :params="params" fields="year-month-day hour-minute"
									@confirm="handleChange"></u-picker>
							</view>
						</view>
						<view class="Pick-Meal-delivery-method">
							<text class="Meal">取餐方式</text>
							<view class="Meal-delivery-method">
								<text>{{ method }}</text>
							</view>
						</view>
						<view class="phone">
							<text>预留电话</text>
							<input type="number" maxlength="11" placeholder="输入电话号码">
						</view>
					</view>

					<view class="take-out-time" v-else>
						<text class="taketime">送达时间</text>
						<!-- 送达时间时间 -->
						<view class="taketime-qu">
							<text style="color: #f14500;">{{ time }}</text>
							<uni-icons type="forward" @click="dateShow = true"></uni-icons>
						</view>
					</view>
				</view>
			</template>
		</view>

		<view class="content">
			<view style="display: flex;justify-content: space-between;align-items: center;padding-top: 20rpx;">
				<view class="content-title">店铺名称</view>
				<view class="content-school">校园专送</view>
			</view>
			<!-- 正常 -->
			<template v-if="source === 0">
				<view class="">
					<view class="content-fast-information" v-for="(item) in arr" :key="item.sku_id">
						<image :src="$image + item.sku_image" mode=""></image>
						<text class="fast-information-name">{{ item.site_name }}</text>
						<text class="fast-information-Setmeal">{{ item.sku_name }}</text>
						<!-- <text class="fast-information-quantity">x{{commodityNum}}</text> -->
						<text class="fast-information-quantity">x{{ item.num }}</text>
						<text class="fast-information-Price">￥{{ item.price }}</text>
					</view>
				</view>
			</template>
			<!-- 秒杀 -->
			<template v-else-if="source === 3">
				<view class="">
					<view class="content-fast-information">
						<image :src="$image + arrMiaoGoods.sku_image" mode=""></image>
						<text class="fast-information-name">{{ arrMiaoGoods.goods_name }}</text>
						<text class="fast-information-Setmeal">{{ arrMiaoGoods.sku_name }}</text>
						<text class="fast-information-quantity">x{{ arrMiaoGoods.num }}</text>
						<text class="fast-information-Price">￥{{ arrMiaoGoods.seckill_price }}</text>
					</view>
				</view>
			</template>
			<!-- 拼团 -->
			<template v-else>
				<view class="">
					<view class="content-fast-information">
						<image :src="$image + arrtuangoods.sku_image" mode=""></image>
						<text class="fast-information-name">{{ arrtuangoods.sku_name }}</text>
						<text class="fast-information-Setmeal">{{ arrtuangoods.goods_name }}</text>
						<text class="fast-information-quantity">x{{ arrtuangoods.num }}</text>
						<text class="fast-information-Price">￥{{ source == 1 ? arrtuangoods.price : source == 2 ?
							arrtuangoods.pintuan_price : '' }}</text>
					</view>
				</view>
			</template>
			<view class="content-package" v-if="packing() != 0">
				<text class="content-package-all">包装费</text>
				<text class="content-package-item" style="color: #f14500;">￥{{ packing() }}</text>
			</view>
			<view class="content-package" v-if="express.local.delivery_money && text == 2">
				<text class="content-package-all">配送费</text>
				<text class="content-package-item" style="color: #f14500;">
					￥{{ express.local.delivery_money }}
				</text>
			</view>
			<view class="content-package" v-if="storeFullReductionArr.length != 0 && discounts > 0">
				<text class="content-package-all">店铺立减</text>
				<!-- <text class="content-package-item" style="color: #f14500;">￥{{data.Originalprice - data.Currentprice}}</text> -->
				<!-- <text class="content-package-item" style="color: #f14500;">-￥{{5}}</text> -->
				<text class="content-package-item" style="color: #f14500;">-{{ discounts }}</text>
				<!-- <text class="content-package-item" style="color: #999;">不到立减要求</text> -->
			</view>
			<!-- 红包 -->
			<view class="content-Red-packet">
				<text class="Red-packet">红包优惠劵</text>
				<view class="Red-packet-quantity" v-if="couponLists.length > 0">
					<view class="packet-quantity-you" style=" border-radius: 5rpx;" @click="evemtCoupon">
						<text class="red-active">使用优惠卷</text>
						>
					</view>
				</view>
				<view v-else class="Red-packet-quantity" style="color: #999;">无优惠券可用 ></view>
			</view>
		</view>

		<view class="mubben" style="text-align: left;">
			<!-- <view class="mubben-Table-setting">
				<text class="Table-setting-title">餐具(筷子、刀、叉、勺)</text>
				<view class="Table-setting" @click="Whetherneed('bottom')">
					<text>{{ Tablesetting }}</text> >
				</view>
			</view> -->
			<view class="mubben-item">
				<text class="mubben-item-notes">餐具(筷子、刀、叉、勺)</text>
				<view class="mubben-item-content" @click="Whetherneed('bottom')">
					<text>{{ Tablesetting }}</text> >
				</view>
			</view>
			<!-- 普通弹窗 -->
			<!-- @change="change" -->
			<uni-popup ref="popup" background-color="#fff">
				<view class="popup-content" style="width: 750rpx; height: 550rpx; background-color: #fff;"
					:class="{ 'popup-height': type === 'left' || type === 'right' }">
					<text class="tables-title">请选择本单餐具</text>
					<uni-icons type="closeempty" class="tables-icon" @click="closes"></uni-icons>
					<view v-for="(item, i ) in tables" :key="i">
						<view class="tables-item" :class="{ active: isActive === i }" @click="tages(i)">
							<text style="float: left; margin-left: 285rpx; margin-top: 24rpx;">{{ item }}</text>
						</view>
					</view>
					<button class="tables-ok" @click="isok"><text>确定</text></button>
				</view>
			</uni-popup>

			<view class="mubben-item">
				<text class="mubben-item-notes">备注</text>
				<!-- @click="zhuan" v-if="bei" -->
				<view class="mubben-item-content">
					<input type="text" class="notesInput" placeholder="口味,偏好等要求" v-model="notes">
				</view>
			</view>
		</view>

		<view class="buttom">
			<view class="buttom-left">
				<text class="button-left-item">
					<text style="color: #181818; font-size: 12px;">￥</text>
					<text style="color: #f14500; font-size: 36rpx;" v-if="source == 0">{{ allPrice.toFixed(2) }}</text>
					<text style="color: #f14500; font-size: 36rpx;" v-else>{{ total }}</text>
					<text style="color: #aaa; font-size: 20rpx; margin-left: 20rpx;">已优惠￥{{ discounts }}</text>
				</text>
			</view>
			<view class="buttom-right" @click="payment()">
				<text style="margin-top: 30rpx; font-size: 31rpx;float: left;margin-left: 27rpx;">提交订单</text>
			</view>
		</view>
		<!-- 支付弹窗 -->
		<u-popup v-model="popups" mode="bottom" border-radius="40">
			<view class="popups-content">
				<i class="payment-cloce" @click="eclose"></i>
				<view class="">
					<text class="payment-way">支付方式</text>
				</view>
				<view class="payment-amount" v-if="source == 0">
					￥<text>{{ allPrice.toFixed(2) }}</text>
				</view>
				<view class="payment-amount" v-else>
					￥<text>{{ total }}</text>
				</view>

				<view class="">
					<uni-data-checkbox v-model="modeOfPayment" :localdata="paymentamount"></uni-data-checkbox>
				</view>
				<view class="payment-button">
					<button @click="immediatePayment">立即支付</button>
				</view>
			</view>
		</u-popup>

		<!-- 优惠券弹框 -->
		<u-popup v-model="couponShow" mode="bottom" border-radius="40">
			<DiscountCoupon :couponList="couponLists" @affirmTicket="affirmTicket"></DiscountCoupon>
		</u-popup>
		<!-- 余额支付 -->
		<u-popup v-model="payShow" mode="bottom" height="900" border-radius="40">
			<PayKeyboard ref="payKeyboardRef" @payWordpass="getPayWordpass"></PayKeyboard>
		</u-popup>
	</view>
</template>

<script>
import PayKeyboard from '@/components/PayKeyboard/index.vue'
import DiscountCoupon from './components/DiscountCoupon.vue'

const $api = require('@/utils/request.js').API

export default {
	components: {
		DiscountCoupon,
		PayKeyboard
	},
	data() {
		return {
			// address: "信阳师范大学一食堂二楼45窗口",
			options: [],
			xiang: 0,
			// 未优惠价格
			originalPrice: 0,
			allPrice: 0,
			arr: [],
			arrgoods: [], // 秒杀，拼团
			arrshop: [],
			arrMiao: [], // 秒杀
			arrMiaoGoods: [],
			arrtuan: [], // 拼团
			arrtuangoods: {},
			express: [], // 门店配送配置
			addressContent: {},
			address_id: '',
			// address: [],
			coupon: {}, //优惠券
			couponLists: [],
			waimaiaddress: [],
			addresskong: false,

			storeFullReductionArr: [], // 店铺满减
			storeFullReductionNum: 0,
			// storeReduction: [],	// 店铺立减
			commodityNum: 0, // 商品数量
			source: 0,
			notes: '', // 备注
			couponShow: false, // 优惠券弹出框
			payShow: false,  //余额支付弹窗
			orderGoodsName: '',
			dateTime: [],
			dateTimezi: [],
			dateTimeShow: false,
			dateTimeShowzi: false,
			dateShow: false,
			params: {
				year: true,
				month: true,
				day: true,
				hour: true,
				minute: true,
				second: false
			},

			init: [], // 待支付订单数据初始化
			initshopgoods: [],

			text: 2,
			time: "",
			show: false,
			method: "打包带走",
			// position: "信阳师范大学1号楼403",
			// Message: "张女士 18776565654",
			shopAddress: [],
			data: {},
			redpacket: 1,
			Tablesetting: "无需餐具",
			type: "center",
			tables: ["无需餐具", "需要餐具"],
			isActive: 0,
			// bei: true,

			popups: false,
			// 支付列表
			paymentamount: [{
				text: '微信支付',
				value: 0
			},
			{
				text: '余额支付',
				value: 1
			},
			],
			// 支付方式
			modeOfPayment: 0,
			$image: this.$image,
			longitude: null, //经度
			latitude: null, //纬度

			// 总价格
			total: 0,
			// 满减金额
			discounts: 0,
			// 配送费
			deliveryMoney: 0,

			// 账户余额
			balance: 0,
			// 拼团id
			pintuan_id: 0
		}

	},

	onLoad: function (option) {
		this.source = Number(option.source)
		if (option.deliveryMoney) {
			this.deliveryMoney = Number(option.deliveryMoney)
		}

		// 秒杀 3，拼团：开团 2 单独 1，正常 0
		if (option.source == 0) {
			this.options = JSON.parse(option.item)
			this.xiang = Number(option.xiang)
			// this.shoppingCartList() // 购物车列表
			this.StoreFullReduction() // 店铺满减
			this.couponList() // 店铺优惠券

		} else if (option.source == 3) {
			this.options = JSON.parse(option.item)
			this.postFlashKillingDetails()
			// this.shoppingCartLists() // 购物车列表
		} else {
			this.options = JSON.parse(option.item)
			this.pintuan_id = option.pintuan_id
			this.productDetailsOfTheGroup() // 拼团详情
			// this.shoppingCartLists() // 购物车列表

		}
		this.commodityDetails() // 商品详情
		this.storeDeliveryConfiguration() //门店配送配置
		// 当前时间
		const datatime = new Date();
		let month = datatime.getMonth() + 1;
		let day = datatime.getDate();
		let hour = datatime.getHours() + 1;
		let minute = datatime.getMinutes();
		month = month > 9 ? month : '0' + month;
		day = day > 9 ? day : '0' + day;
		hour = hour > 9 ? hour : '0' + hour;
		minute = minute > 9 ? minute : '0' + minute;
		this.time = `${month}月${day}日(今日)${hour}:${minute}`
	},
	onShow() {
		if (uni.getStorageSync('address')) {
			let id = uni.getStorageSync('address')
			this.addressInformation(id)
			this.addresskong = true
		} else {
			this.addresskong = false
			this.addressList() // 地址列表
		}
		let thas = this
		uni.getLocation({
			type: 'wgs84',
			success: function (res) {
				thas.longitude = res.longitude
				thas.latitude = res.latitude
			}
		})
	},
	onHide() {
		uni.removeStorageSync('address')
	},
	computed: {

	},
	methods: {

		// 确定优惠券
		affirmTicket(value) {
			this.allPrice = this.originalPrice
			this.coupon = value
			this.discounts = value.money
			this.allPrice = this.allPrice - value.money
			this.couponShow = false

		},

		// 门店配送配置
		storeDeliveryConfiguration() {
			if (this.source === 0 || this.source === 3) {
				if (this.xiang == 0) {
					let site_id = 0
					this.options.forEach(item => {
						site_id = item.site_id
					})
					this.mendian(site_id)
				} else {
					let site_id = this.options.goods_sku_detail.site_id
					this.mendian(site_id)
				}
			} else if (this.source === 1 || this.source === 2) {
				let site_id = this.options.goods_sku_detail.site_id
				this.mendian(site_id)
			}
		},
		// 获取包装费
		mendian(site_id) {
			$api.postStoreDeliveryConfiguration({
				site_id: site_id
			}).then(res => {
				this.express = res.data.data
				if (this.source == 0) {
					this.shoppingCartList() // 购物车列表
				}
			})
		},
		// 秒杀详情
		postFlashKillingDetails() {
			// this.options.goods_sku_detail.seckill_id

			$api.postFlashKillingDetails({
				seckill_id: this.options[0].seckill_id
			}).then(res => {
				if (res.data.code == 0) {
					this.arrMiao = res.data.data
					this.arrMiaoGoods = res.data.data.goods_sku_detail
					this.arrMiaoGoods.num = this.options[0].num
					this.arrgoods = res.data.data.goods_sku_detail
					this.arrshop = res.data.data.shop_info
					this.actualamount();
				}
			})
			// }
			// })
		},
		// 拼团详情
		productDetailsOfTheGroup() {
			console.log('this.pintuan_id', this.pintuan_id);
			$api.postProductDetailsOfTheGroup({
				pintuan_id: this.pintuan_id
			}).then(res => {
				this.arrtuan = res.data.data
				this.arrtuangoods = res.data.data.goods_sku_detail
				this.arrgoods = res.data.data.goods_sku_detail
				this.arrshop = res.data.data.shop_info
				this.shoppingCartListstuan()
			})
		},
		// 商品详情
		commodityDetails() {
			let sku_id = 0
			if (this.source == 0) {
				if (this.xiang == 0) {
					this.options.forEach(item => {
						sku_id = item.sku_id
					})
				} else {
					sku_id = this.options.goods_sku_detail.sku_id
				}
			} else if (this.source == 3) {
				sku_id = this.options[0].sku_id
			} else {
				sku_id = this.options.goods_sku_detail.sku_id
			}
			$api.postCommodityDetails({
				sku_id: sku_id
			}).then(res => {
				this.arrgoods = res.data.data.goods_sku_detail
				this.arrshop = res.data.data.shop_info
				this.shopAddress = res.data.data.shop_info
			})
		},
		// 购物车列表
		shoppingCartList() {
			if (this.source == 0) {
				let site_id = 0
				if (this.xiang == 0) {
					this.options.forEach(item => {
						site_id = item.site_id
					})
				} else {
					site_id = this.options.goods_sku_detail.site_id
				}
				$api.postShoppingCartList({
					// token: uni.getStorageSync('token'),
					site_id: site_id,
					// site_id: this.options.goods_sku_detail.site_id
				}).then(res => {
					if (res.data.code == 0) {
						this.arr = res.data.data
						this.initializationOfPendingOrderData()

						this.actualamount()
					}
				})
			}

		},
		shoppingCartLists() {

			// this.options.goods_sku_detail.site_id
			$api.postShoppingCartList({
				// token: uni.getStorageSync('token'),
				site_id: this.options[0].site_id
			}).then(res => {
				if (res.data.code == 0) {
					// this.arr = res.data.data
				}
			})
		},
		// 拼团购物车列表
		shoppingCartListstuan() {
			$api.postShoppingCartList({
				site_id: this.arrtuangoods.site_id
			}).then(res => {
				if (res.data.code == 0) {
					this.arr = res.data.data

					let goods= res.data.data.find(item => {
						return this.arrtuangoods.goods_id == item.goods_id
					})
					this.arrtuangoods = { ...this.arrtuangoods, ...goods }
					this.total = Number(this.totalPrice())

				}
			})
		},
		// 店铺满减
		StoreFullReduction() {
			let site_id = 0
			if (this.source == 0) {
				if (this.xiang == 0) {
					this.options.forEach(item => {
						site_id = item.site_id
					})
				} else {
					site_id = this.options.goods_sku_detail.site_id
				}
			} else {
				site_id = this.options.goods_sku_detail.site_id
			}
			$api.postStoreFullReduction({
				site_id: site_id
			}).then(res => {
				if (res.data.code == 0) {
					this.storeFullReductionArr = res.data.data
				}
			})
		},
		// 店铺优惠券
		couponList() {
			$api.postCouponShop({
				state: 1,
			}).then(res => {
				this.couponLists = res.data.data.list
				this.getyouhuijaun()
			})
		},
		// 地址列表
		addressList() {
			$api.postAddressList({}).then(res => {
				res.data.data.list.filter(item => {
					if (item.is_default == 1) {
						this.waimaiaddress = res.data.data.list
						this.addressInformation(item.id)
						this.addresskong = true
					}
				})
			})
		},
		// 地址信息
		addressInformation(id) {
			$api.postAddressInformation({
				id: id
			}).then(res => {
				this.waimaiaddress = res.data.data
			})
		},
		// 待支付订单数据初始化
		initializationOfPendingOrderData() {
			let cart_id = []
			this.arr.forEach(item => {
				cart_id.push(item.cart_id)
			})
			$api.postInitializationOfPendingOrderData({
				cart_ids: String(cart_id)
			}).then(res => {
				this.init = res.data.data
				// if(this.text == 1) {
				this.initshopgoods.push(res.data.data.shop_goods_list)
				// }
			})
		},
		// 点击立即支付
		payment() {
			if (!this.addresskong) {
				uni.showToast({
					title: '请选择收货地址',
					icon: 'none',
					duration: 2000
				})
				return
			}
			// 获取账户余额
			$api.postUserInformation().then(res => {
				let balance = res.data.data.balance
				if (Number(balance) < this.allPrice.toFixed(2)) {
					this.paymentamount = [this.paymentamount[0]]
				}
				this.popups = true
			})
		},

		// 创建订单
		createOrder(type) {
			let wait = null
			this.type = type
			let site_id = 0
			let cart_ids = []
			let store_id = 0
			if (this.source == 0) {
				this.arr.forEach(item => {
					site_id = item.site_id
					cart_ids.push(item.cart_id)
				})
			} else if (this.source == 2 || this.source == 1) {
				site_id = this.arrtuangoods.site_id
			} else if (this.source == 3) {
				site_id = this.arrMiaoGoods.site_id
			}

			// 配送信息
			let delivery = {}
			if (this.text == 1) {
				this.initshopgoods.forEach((item, index) => {
					item[site_id].express_type.filter(i => {
						if (i.store_id) {
							store_id = i.store_id
						}
					})
				})
				delivery = { // 配送信息
					[site_id]: {
						"delivery_type": this.text == 1 ? 'store' : 'local',
						"delivery_type_name": this.text == 1 ? '门店自提' : '外卖配送',
						"store_id": store_id,
						"buyer_ask_delivery_time": this.text == 1 ? dateTimes : this.time,
					},
				}
			} else {
				this.initshopgoods.forEach((item, index) => {
					item[site_id].express_type.filter(i => {
						if (i.store_id) {
							store_id = i.store_id
						}
					})
				})
				delivery = { // 配送信息
					[site_id]: {
						"delivery_type": this.text == 1 ? 'store' : 'local',
						"delivery_type_name": this.text == 1 ? '门店自提' : '外卖配送',
						"buyer_ask_delivery_time": this.text == 1 ? dateTimes : this.time,
					},
				}
			}

			let dateTimes = this.dateTime.year + '-' + this.dateTime.month + '-' + this.dateTime.day + ' ' + this
				.dateTime.hour + ':' + this.dateTime.minute
			// 送餐地址
			let member_address = {
				name: this.text == 1 ? this.waimaiaddress.name : this.waimaiaddress.name,
				mobile: this.text == 1 ? this.waimaiaddress.mobile : this.waimaiaddress.mobile,
				address: this.text == 1 ? this.shopAddress.address : this.waimaiaddress.address,
				house_number: this.text == 1 ? this.waimaiaddress.house_number : this.waimaiaddress.house_number,
				longitude: this.waimaiaddress.longitude,
				latitude: this.waimaiaddress.latitude,
			}
			// 备注
			let buyer_message = {
				[site_id]: this.notes,
			}
			// "longitude":"114.038213","latitude":"32.138275"
			if (this.source === 0) {
				wait = $api.postOrderGoodsSubmitTo({
					cart_ids: String(cart_ids),
					delivery: JSON.stringify(delivery),
					is_balance: this.modeOfPayment, //0是微信支付 1 是余额支付
					balance_money: this.allPrice.toFixed(2),  //余额支付的数额
					platform_coupon_id: this.coupon.platformcoupon_id, // 平台优惠券id
					platform_coupon_money: this.coupon.money, // 平台优惠券金额
					member_address: JSON.stringify(member_address), // 送餐地址
					buyer_message: JSON.stringify(buyer_message), // 备注
					coupon: JSON.stringify(this.coupon), // 店铺优惠券
					tableware: this.isActive, // 餐具
					store_id: store_id,
				}).then(res => {
					if (res.data.code == 0) {
						this.orderGoodsName = res.data.data
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 2000
						})
					}

				}).catch(err => {
					console.error(err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 2000
					})
				})
			} else if (this.source === 3) {
				wait = $api.postFlashKillingOrderSubmission({
					seckill_id: this.arrMiaoGoods.seckill_id, // 秒杀id
					num: this.arrMiaoGoods.num, // 商品数量
					sku_id: this.arrMiaoGoods.sku_id, // 商品的skuid 
					buyer_message: JSON.stringify(buyer_message), // 备注
					delivery: JSON.stringify(delivery),// 配送信息
					is_balance: this.modeOfPayment, // 1 是余额支付
					member_address: JSON.stringify(member_address), // 送餐地址
					longitude: this.longitude,
					latitude: this.latitude,
				}).then(res => {
					if (res.data.code == 0) {
						this.orderGoodsName = res.data.data
					} else {
						uni.showToast({
							title: 'cuowu',
							icon: 'none',
							duration: 2000
						})
					}
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 2000
					})
				})
			} else {
				wait = $api.postGroupOrderSubmission({
					is_balance: this.modeOfPayment, // 1 是余额支付
					pintuan_goods_id: this.arrtuangoods.id, // 拼团商品详情里的id
					group_id: 0, // 拼团组id,商品发起拼团的列表获得,如果此接口返回空数组传0,如果有数据就传返回的group_id
					num: this.arrtuangoods.num, // 商品数量
					buyer_message: JSON.stringify(buyer_message), // 备注
					delivery: JSON.stringify(delivery), // 配送信息
					member_address: JSON.stringify(member_address), // 送餐地址
					longitude: this.longitude,
					latitude: this.latitude,
				}).then(res => {
					if (res.data.code == 0) {
						this.orderGoodsName = res.data.data
						console.log(this.orderGoodsName);
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 2000
						})
					}
				})
			}
			return wait
		},
		// 立即支付
		immediatePayment() {
			if (this.modeOfPayment == 0) {
				let result = this.createOrder('bottom')
				if (result == null) {
					return
				}
				Promise.all([result]).then(() => {
					// 微信支付
					$api.postOrderGoodsPayment({
						out_trade_no: this.orderGoodsName,
						pay_type: 'wechatpay',
						is_matched: 0,
					}).then(res => {
						let obj = res.data.data.data
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: obj.timeStamp,
							nonceStr: obj.nonceStr,
							package: obj.package,
							signType: obj.signType,
							paySign: obj.paySign,
							success: function (res) {
								uni.navigateTo({
									url: '../../pages/Paymentcompletion/Paymentcompletion?source=' + 1
								})
							},
							fail: function (err) {
								uni.navigateTo({
									url: '../../pages/Paymentcompletion/Paymentcompletion?source=' + 2
								})
							}
						});
					})
				})
			} else {
				// 余额支付
				this.payShow = true
				this.popups = false
				this.$refs.payKeyboardRef.onPayUp();
			}

		},
		//获取余额支付支付密码
		getPayWordpass(wordpass) {
			$api.checkpaypassword({ pay_password: wordpass }).then(res => {
				let result = this.createOrder('bottom')
				console.log(result, "-====result")
				if (result == null) {
					return
				}
				Promise.all([result]).then(res => {
					uni.navigateTo({
						url: '/pages/Paymentcompletion/Paymentcompletion?source=' + 1
					})
				})
			}).catch(err => {
				console.log(err);
			})
		},
		// 优惠券
		evemtCoupon() {
			this.couponShow = true

		},
		// 平台优惠卷
		getyouhuijaun() {
			$api.postCouponAssemble({ state: 1, page_size: 100 }).then(res => {
				this.couponLists = [...res.data.data.list, ...this.couponLists]
				this.couponLists = this.couponLists.filter(item => {
					return Number(this.originalPrice) > Number(item.at_least)
				})
			})
		},
		// 选择地址
		selectAddress() {
			uni.navigateTo({
				url: '/pages_my/my/giveServiceTo/address?source=' + 0
			})
		},
		// 时间
		handleChange(val) {
			this.dateTime = val
			this.dateTimeShow = true
		},
		handleChangezi(val) {
			this.dateTimezi = val
			this.dateTimeShowzi = true
		},
		showPopup() {
			this.setData({
				show: true
			});
		},
		onClose() {
			this.setData({
				show: false
			});
		},
		// 点击切换自提/外卖
		textfalse() {
			if (this.text == 1) {
				this.text = 2;
			} else {
				this.text = 1;
			}
			this.actualamount()
		},
		// 是否需要餐具
		Whetherneed(type) {
			this.type = type
			// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
			this.$refs.popup.open(type)
		},
		// 关闭弹窗
		closes() {
			this.$refs.popup.close()
		},
		// 点击切换是否携带餐具
		tages(i) {
			this.isActive = i;
		},
		isok() {
			this.Tablesetting = this.tables[this.isActive]
			this.$refs.popup.close()
		},

		zhi(e) {
			if (e.detail.value) {
				this.remark = e.detail.value
			}
			this.bei = true
		},
		// 点击支付弹窗的关闭
		eclose() {
			this.popups = false
			uni.navigateBack()
		},
		// 满减后的价格
		actualamount() {
			let _this = this
			if (this.source == 0) {
				this.total = Number(this.totalPrice())
				console.log(this.total, "=========his.total=========")
				// 			店铺满减
				if (this.storeFullReductionArr.length != 0) {
					let obj = this.storeFullReductionArr.filter(item => item.money <= this.total)
					// 满减条件1
					if (obj.length != 0) {
						_this.allPrice = this.total - obj[obj.length - 1].discount_money
						// 优惠价格
						this.discounts = obj[obj.length - 1].discount_money
					} else {
						// 满减条件2
						_this.allPrice = this.total
					}
				} else {
					_this.allPrice = this.total
				}
				if (_this.text == 2) {  //自提时不需要计算配送费用
					_this.allPrice = _this.allPrice + this.deliveryMoney
				}
				_this.originalPrice = _this.allPrice
				this.couponList() // 店铺优惠券

			} else if (this.source == 3) {
				this.total = Number(this.totalPrice())
				if (_this.text == 2) {  //自提时不需要计算配送费用
					_this.allPrice = _this.allPrice + this.deliveryMoney
				}
				_this.originalPrice = _this.allPrice
			}
		},
		// 包装费
		packing() {
			// let num = 0
			var pack_money = 0;
			if (this.express.local) {
				pack_money = this.express.local.pack_money
			}
			// this.arr.forEach(item => {
			// 	num += pack_money * item.num
			// })
			return pack_money
		},
		// 总价
		totalPrice() {
			if (this.source === 0) {
				let num = 0
				let pack_money = 0;
				if (this.express && this.express.local && this.express.local.pack_money) {
					pack_money = this.express.local.pack_money
				}
				this.arr.forEach(item => {
					this.commodityNum = item.num
					num += (item.price * item.num)
					// num += (item.price * item.num) + (pack_money * item.num)
				})
				num = num + Number(pack_money)
				return num.toFixed(2)
			} else if (this.source === 3) {
				let num = 0;
				num = this.arrMiaoGoods.seckill_price * this.arrMiaoGoods.num
				let pack_money = 0;
				if (this.express && this.express.local && this.express.local.pack_money) {
					pack_money = this.express.local.pack_money
				}
				console.log(pack_money, "===============pack_money")
				num = num + Number(pack_money)

				if (this.text == 2) {  //自提时不需要计算配送费用
					num = num + this.deliveryMoney
				}
				return num;
			} else if (this.source == 2) {
				console.log(' this.arrtuangoods.num', this.arrtuangoods.num);
				let num = 0
				num += this.arrtuangoods.pintuan_price * this.arrtuangoods.num + this.deliveryMoney
				return num
			} else if (this.source == 1) {
				console.log(this.arrtuangoods.price, "<<<<<<<<<<<<<")
				let num = 0;
				num = this.arrtuangoods.price * this.arrtuangoods.buy_num
				let pack_money = 0;
				if (this.express && this.express.local && this.express.local.pack_money) {
					pack_money = this.express.local.pack_money
				}
				console.log(pack_money, "===============pack_money")
				num = num + Number(pack_money)

				if (this.text == 2) {  //自提时不需要计算配送费用
					num = num + this.deliveryMoney
				}
				return num;
			}
		},
	}
}
</script>

<style lang="less" scoped>
.box {
	width: 750rpx;
	// height: 1404rpx;
	background-color: #FBFBFB;
	text-align: center;
	position: relative;

	// .address {
	// 	height: 70rpx;
	// 	background: pink;
	// }
	.dizhi {
		width: 500rpx;
	}

	.top {
		width: 702rpx;
		display: inline-block;
		margin-top: 18rpx;
		margin-bottom: 18rpx;
		text-align: left;
		border-radius: 20rpx;
		overflow: hidden;
		padding: 34rpx 0;
		background-color: #fff;

		// margin-left: 24rpx;
		// 自提配置
		.Pick-up-at-home {
			width: 100%;
			height: 100%;
			background-color: #fff;
			position: relative;

			// 按钮-
			.Button {
				position: absolute;
				// top: 30rpx;
				right: 19rpx;
			}

			.Pick-shopping {
				display: block;
				// width: 110rpx;
				height: 27rpx;
				line-height: 27rpx;
				// margin-top: 34rpx;
				margin-left: 27rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #202020;

				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.Pick-address {
				height: 23rpx;
				line-height: 23rpx;
				display: block;
				margin-top: 22rpx;
				margin-left: 27rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #8F8F8F;

				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.quxuanzeaddress {
				margin: 27rpx;
			}

			.Pick-time {
				width: 100%;
				height: 27rpx;
				margin-top: 32rpx;
				margin-bottom: 14rpx;

				.time {
					float: left;
					// width: 109rpx;
					height: 27rpx;
					line-height: 27rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #202020;
					margin-left: 28rpx;
				}

				.time-qu {
					height: 27rpx;
					line-height: 27rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					float: right;
					margin-right: 26rpx;
				}
			}

			.Pick-Meal-delivery-method {
				width: 100%;
				height: 35rpx;
				margin-bottom: 24rpx;

				.Meal {
					float: left;
					width: 109rpx;
					height: 35rpx;
					line-height: 35rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #202020;
					margin-left: 28rpx;
				}

				.Meal-delivery-method {
					width: 108rpx;
					height: 35rpx;
					background-color: #f14500;
					border-radius: 50rpx;
					overflow: hidden;
					text-align: center;
					line-height: 35rpx;

					text {
						display: block;
						width: 100%;
						height: 100%;
						text-align: center;
						line-height: 100%;
						font-size: 20rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #FFFFFF;
						margin-top: 4rpx;
					}
				}
			}

			// 预留电话
			.phone {
				display: flex;
				align-items: center;
				width: 702rpx;
				height: 69rpx;
				background: #E4E9E8;
				border-radius: 0rpx 0rpx 10rpx 10rpx;

				text {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #202020;
					padding: 0 40rpx 0 28rpx;
				}
			}
		}

		// 外卖配置
		.take-out {
			width: 100%;
			height: 100%;
			padding-top: 10rpx;
			padding-bottom: 10rpx;
			background-color: #fff;

			.Button2 {
				position: absolute;
				top: 30rpx;
				right: 19rpx;
			}

			.take-out-position {
				display: block;
				margin-left: 27rpx;
				margin-bottom: 29rpx;
				height: 27rpx;
				font-size: 28rpx;
				font-weight: 500;
				color: #262626;
				line-height: 30rpx;
			}

			.take-out-Message {
				height: 20rpx;
				display: block;
				margin-left: 27rpx;
				font-size: 20rpx;
				font-weight: 400;
				color: #8F8F8F;
				line-height: 30rpx;
				margin-bottom: 37rpx;
			}


		}
	}

	.content {
		display: inline-block;
		width: 702rpx;
		background-color: #FFFFFF;
		text-align: left;
		border-radius: 10rpx;
		margin-bottom: 19rpx;

		.content-title {
			width: 118rpx;
			height: 28rpx;
			display: block;
			margin-left: 29rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #4A4A4A;
			margin-bottom: 33rpx;
		}

		.content-school {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 143rpx;
			height: 49rpx;
			border: 1px solid #F14500;
			border-radius: 24rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #F14500;
			margin-right: 24rpx;
		}

		.content-fast-information {
			width: 100%;
			height: 102rpx;
			// text-align: left;
			position: relative;
			margin-bottom: 28rpx;

			image {
				width: 102rpx;
				height: 102rpx;
				margin-left: 27rpx;
			}

			.fast-information-name {
				height: 25rpx;
				line-height: 25rpx;
				position: absolute;
				top: 0;
				left: 141rpx;
				font-size: 26rpx;
				font-weight: 400;
				color: #333333;
			}

			.fast-information-Setmeal {
				height: 23rpx;
				position: absolute;
				line-height: 23rpx;
				bottom: 10rpx;
				left: 140rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #898989;
			}

			.fast-information-quantity {
				height: 18rpx;
				line-height: 18rpx;
				position: absolute;
				top: 40rpx;
				left: 486rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #898989;
			}

			.fast-information-Price {
				height: 24rpx;
				line-height: 24rpx;
				position: absolute;
				top: 37rpx;
				right: 35rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #373737;
			}
		}

		.content-package {
			width: 100%;
			height: 25rpx;
			line-height: 25rpx;
			margin-bottom: 28rpx;

			.content-package-all {
				display: block;
				height: 25rpx;
				float: left;
				margin-left: 28rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #202020;
			}

			.content-package-item {
				display: block;
				float: right;
				margin-right: 33rpx;
				height: 22rpx;
				line-height: 22rpx;
			}
		}

		.content-Red-packet {
			height: 25rpx;
			margin-bottom: 41rpx;

			.Red-packet {
				display: block;
				width: 128rpx;
				height: 41rpx;
				float: left;
				margin-left: 28rpx;
				line-height: 41rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #202020;
			}

			.Red-packet-quantity {
				// width: 70px;
				height: 29rpx;
				float: right;
				margin-right: 34rpx;

				// 无优惠卷
				.packet-quantity {
					line-height: 29rpx;
					// font-size: 18rpx;
					font-size: 22rpx;
					font-family: PingFang SC;
					font-weight: 400;
					margin-right: 10rpx;
				}

				.packet-quantity-you {
					width: 100%;
					height: 100%;

					.red-active {
						display: inline-block;
						background-color: #f14500;
						color: #fff;
						padding: 6rpx 10prx;
					}
				}
			}
		}
	}

	// 餐具和备注
	.mubben {
		width: 702rpx;
		border-radius: 5rpx;
		margin: auto;
		background-color: #fff;

		.mubben-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 64rpx;
			padding: 0 24rpx 0 30rpx;

			.mubben-item-notes {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #4A4A4A;
			}

			.mubben-item-content {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #515151;
			}

			.notesInput {
				text-align: right;
			}
		}

		// 是否需要餐具的弹窗
		.popup-content {
			position: relative;
			padding: 51rpx 34rpx;

			.tables-title {
				display: inline-block;
				width: 100%;
				height: 33rpx;
				line-height: 33rpx;
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #262525;
				margin-bottom: 43rpx;
			}

			.tables-icon {
				position: absolute;
				top: 40rpx;
				right: 40rpx;
			}

			.tables-clock {
				display: block;
				width: 28rpx;
				height: 28rpx;
				position: absolute;
				top: 43rpx;
				right: 34rpx;
			}

			.tables-item {
				width: 681rpx;
				height: 88rpx;
				margin-bottom: 42rpx;
				border: 2rpx solid #9e9e9e;
			}

			.active {
				border-color: #E74D0A;
				color: #E74D0A;
			}

			.tables-ok {
				width: 682rpx;
				height: 88rpx;
				background-color: #E74D0A;
				color: #fff;
				margin: 0;
				border-radius: 44rpx;
				position: fixed;
				left: 33rpx;
				bottom: 47rpx;
			}
		}
	}

	.buttom {
		width: 702rpx;
		height: 103rpx;
		position: fixed;
		left: 25rpx;
		bottom: 30rpx;
		// bottom: 66rpx;
		margin: auto;
		margin-top: 20rpx;
		border-radius: 50rpx;
		overflow: hidden;
		background-color: #fff;

		.buttom-left {
			float: left;
			width: 504rpx;
			height: 103rpx;
			position: relative;

			.button-left-item {
				height: 29rpx;
				position: absolute;
				top: 38rpx;
				left: 48rpx;
				line-height: 29rpx;
			}
		}

		.buttom-right {
			float: left;
			width: 195rpx;
			height: 103rpx;
			background: linear-gradient(90deg, #FFB365 0%, #F14500 100%);
			color: #fff;
			text-align: center;
		}
	}

	// 支付弹窗
	.popups-content {
		width: 750rpx;
		position: relative;
		border-radius: 40px;
		padding-top: 30rpx;

		.payment-cloce {
			display: block;
			width: 44.3rpx;
			height: 44.3rpx;
			background-image: url(../../static/关闭.png);
			background-position: center center;
			background-repeat: no-repeat;
			background-size: 44.3rpx 44.3rpx;
			position: absolute;
			top: 41rpx;
			left: 34rpx;
		}

		.payment-way {
			text-align: center;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 56rpx;
		}

		.payment-amount {
			height: 62rpx;
			text-align: center;
			font-size: 41rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #000000;
			line-height: 60rpx;
			padding: 20rpx 0 30rpx 0;

			text {
				font-size: 80rpx;
			}
		}

		::v-deep .checklist-group {
			width: 100%;
			height: 80rpx;
			margin: 20rpx 30rpx;

			.checklist-box {
				display: block;
				width: 100%;
				height: 49.3rpx;
				margin-bottom: 30rpx;

				.checklist-content {
					float: left;
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #333333;
					line-height: 121rpx;
				}

				.radio__inner {
					float: right;
				}
			}

			.is-checked {
				color: #F14500 !important;
			}
		}

		.payment-button {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 30rpx 0 62rpx 0;
			margin-top: 80rpx;

			button {
				width: 664.4rpx;
				height: 88.5rpx;
				background-color: #f14500;
				color: #fff;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				border-radius: 44rpx;
				line-height: 88.5rpx;
			}
		}
	}
}

.take-out-time {
	width: 100%;
	height: 27rpx;
	margin-top: 37rpx;

	.taketime {
		width: 119rpx;
		height: 27rpx;
		line-height: 27rpx;
		font-size: 28rpx;
		float: left;
		margin-left: 27rpx;
		font-weight: 500;
		color: #202020;
	}

	.taketime-qu {
		float: right;
		margin-right: 26rpx;
		height: 27rpx;
		line-height: 27rpx;
	}
}

// 购物车商品列表
.commodity {
	padding: 59rpx 32rpx 64rpx 41rpx;

	.commodity-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-bottom: 48rpx;

		.commodity-title-left {
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;

			.pack {
				font-size: 24rpx;
				color: #878787;
				padding-left: 20rpx;
			}

			.fee {
				font-size: 24rpx;
				color: #E64403;
				padding-left: 10rpx;
			}
		}

		.commodity-title-right {
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #A3A3A3;
		}
	}

	.commodity-main {
		display: flex;
		align-items: center;
		padding-bottom: 30rpx;

		.commodity-main-image {
			padding-right: 26rpx;

			image {
				width: 180rpx;
				height: 180rpx;
				border-radius: 10rpx;
			}
		}

		.commodity-main-right {
			.title {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}

			.notes {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #A3A3A3;
				padding: 30rpx 0 30rpx 0;
			}

			.price {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 474rpx;

				.price-left {
					text:first-child {
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #F14500;
					}

					text:last-child {
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 400;
						text-decoration: line-through;
						color: #A3A3A3;
					}
				}

				// .price-right {}
			}
		}
	}
}
</style>